// Is it a tree?
#include <iostream>
#include <cmath>
using namespace std;

int set[10001];
int points[10001][2];

int find(int r)
{
    while (set[r] != r)
    {
        r = set[r];
    }
    return r;
}

void merge(int a, int b)
{
    int r1 = find(a);
    int r2 = find(b);
    if (r1 != r2)
    {
        set[b] = a;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int testcases = 0;
    int position, maxvalue;
    int point1, point2;
    bool tree;
    while(true)
    {
        cin >> point1 >> point2;
        if(point1 == -1 && point2 == -1)
        {
            break;
        }
        // 每次循环前数值初始化
        testcases += 1;
        position = 1;
        tree = true;
        maxvalue = 0;
        while(true)
        {
            if(point1 == 0 && point2 == 0)
            {
                break;
            }
            points[position][0] = point1;
            points[position][1] = point2;
            maxvalue = max(max(maxvalue, point1), point2);
            cin >> point1 >> point2;
            position += 1;
        }
        position -= 1;
        for(int i=1; i<=maxvalue; i++)
        {
            set[i] = i;
        }
        for(int i=1; i<=position; i++)
        {
            if (set[points[i][1]] == points[i][1])
            {
                // merge(points[i][0], points[i][1]);
                set[points[i][1]] = points[i][0];
            }
            else
            {
                tree = false;
                break;
            }
        }
        if(tree)
        {
            cout << "Case " << testcases << " is a tree." << "\n";
        }
        else
        {
            cout << "Case " << testcases << " is not a tree." << "\n";
        }
    }
}